package cn.congzhou.crm.domain;

import cn.congzhou.crm.utils.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter@Setter@ToString
@AllArgsConstructor
@NoArgsConstructor
public class Customer {
    public static final Integer STATUS_POSS = 0;//潜在客户
    public static final Integer STATUS_FAILED = 1;//开发失败
    public static final Integer STATUS_PRED = 2;//重点关注
    public static final Integer STATUS_POOL = 3;//客户池
    public static final Integer STATUS_FORMAL = 4;//正式客户

    private Long id;

    private String name;//姓名

    private Integer age;//年龄

    private Integer gender;//性别

    private String tel;//电话号码

    private String job;//职业

    private SystemDictionaryItem source;//来源

    private SystemDictionaryItem curriculum;//意向课程

    private Employee seller;//销售员

    private Employee inputUser;//录入数据人

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date inputTime;

    private Integer status;

    private String remark;


    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("age", age);
        map.put("gender", gender);
        map.put("tel", tel);
        map.put("job", job);
        if(source != null){
            map.put("sourceId", source.getId());
        }
        if(seller != null){
            map.put("sellerName", seller.getName());
            map.put("sellerId", seller.getId());
        }
        if (curriculum != null){
            map.put("curriculumId",curriculum.getId());
            map.put("curriculumName",curriculum.getTitle());
        }
        map.put("inputUser", inputUser);
        if(inputTime != null){
            String time = DateUtil.formatDate(inputTime);
            map.put("inputTime", time);
        }
        map.put("status", status);
        map.put("remark", remark);

        return JSON.toJSONString(map);
    }

//  转换性别为字符串
    public String getGenderName(){
        if(gender == null){
            return "";
        }
        if(gender == 0){
            return "女";
        }else if(gender == 1){
            return "男";
        }
        return "";
    }



    //  转换状态为字符串
    public String getStatusName(){
        if(status == null){
            return null;
        }
        if(status==0){
            return "潜在客户";
        }
        if(status==1){
            return "开发失败";
        }
        if(status==2){
            return "重点关注";
        }
        if(status==3){
            return "移入客户池";
        }
        if(status==4){
            return "正式客户";
        }
        return null;
    }


}